$("#chevericode").on("click",function(){
	$(".codepic img").attr("src","../img/codepic/"+Math.floor(Math.random()*6)+".jpg");
});
var _initRegExp = {
    chkphone:function(str){
        var reg=new RegExp("^0?(13|15|18|14|17)[0-9]{9}$");
        return reg.test(str);
    },
	chkPassword:function(str){
		var reg = new RegExp("^[A-Za-z0-9]{6,20}$");
		return reg.test(str);
	}
}
var fpwd = false,fphone = false,frpwd= false;fcode=false;
$("#titphone").blur(function(){
	var telval=$("#titphone").val();
	if(telval==""||telval==undefined){
		$(".ischeck").eq(0).css("display","block");
		fphone = false;
	}else if(_initRegExp.chkphone($.trim(telval))){
		$(".ischeck").eq(0).css("display","block").find("img").attr("src","../img/codepic/"+11+".jpg");
		fphone = true;
	}else{
		$(".ischeck").eq(0).css("display","block");
		fphone = false;
	}
})
$("#titpassword").blur(function(){
	var passval=$("#titpassword").val();
	if(passval==""||passval==undefined){
		$(".ischeck").eq(1).css("display","block");
		fpwd = false;
	}else if(_initRegExp.chkPassword($.trim(passval))){
		$(".ischeck").eq(1).css("display","block").find("img").attr("src","../img/codepic/"+11+".jpg");
		fpwd = true;
	}else{
		$(".ischeck").eq(1).css("display","block");
		fpwd = false;
	}
})
$("#repassword").blur(function(){
	var repassval=$("#repassword").val();
	if(repassval==""||repassval==undefined){
		$(".ischeck").eq(2).css("display","block");
		frpwd= false;
	}else if(repassval==$("#titpassword").val()){	
		$(".ischeck").eq(2).css("display","block").find("img").attr("src","../img/codepic/"+11+".jpg");
		frpwd= true;
	}
})
$("#vericode").blur(function(){
	var arr=["oton","iize","ineg","zesa","ayat","huva"];
	var src=$(".codepic img").attr("src");
	// console.log(src) ;../img/codepic/0.jpg
	var picNum=src.split("/")[3].charAt(0);
	console.log(picNum)
	var codeval=$("#vericode").val();
	if(codeval==arr[picNum]){
		$(".ischeck").eq(3).css("display","block").find("img").attr("src","../img/codepic/"+11+".jpg");
		fcode= true;
	}else{
		$(".ischeck").eq(3).css("display","block");
		fcode= false;
	}
})
$(".abtn-a1").click(function(){
	if(fcode&&fpwd&&frpwd&&fphone){
		username=$("#titphone").val();
		setCookie();
		window.location.href="login.html?username="+username;
	}
})
$(".abtn-a2").click(function(){
	window.location.href="login.html"
})
$("input").focus(function(){
	console.log(1)
	$(this).css("box-shadow","0 0 5px #4CEC81");
})
function setCookie(){
	var password=$("#titpassword").val();
	var d=new Date();
	d.setDate(d.getDate()+30)
	document.cookie="user="+username+";expires="+d;
	document.cookie="pwd="+password+";expires="+d;
}